/*
 * User: rant
 * Date: 12/02/2007
 *
 *
 */
package laMalinche.rete.nodes.editing;

import laMalinche.editableContext.CertaintyChangeEvent;
import laMalinche.rete.conditions.FieldCondition;
import laMalinche.actObservable.BasicActObservableCondition;

import java.util.*;

/**
 This certainty manager is true only on the when a relevant field became into editing context
 */
public class IntoTaskCertaintyManager extends OpenFieldCertaintyManager {
	private boolean isCertain;

	@Override
	public void certaintyChange(CertaintyChangeEvent e) {
		final Set<String> becameInEditing = e.getBecameInEditing();
		final String relevantField = getRelevantField();
		if (becameInEditing != null &&
				becameInEditing.contains(relevantField)) {
			isCertain = true;
			adviseListeners(true);
			isCertain = false;
		}
	}

	private String getRelevantField() {
		return ((FieldCondition) ((BasicActObservableCondition) getConditionNode().getCondition()).getCondition()).getOgnl();
	}

	@Override
	public boolean isCertain() {
		return isCertain;
	}
}